package com.sky.controller.user;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sky.dto.UserLoginDTO;
import com.sky.pojo.Category;
import com.sky.pojo.Setmeal;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import com.sky.service.admin.UserService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.UserLoginVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;
import java.util.List;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Slf4j
public class UserController {
    private final UserService userService;


    /*
     * 小程序登录
     * */
    @PostMapping("/user/login")
    public Result weChatLogin(@RequestBody UserLoginDTO dto){

        UserLoginVO userLoginVO = userService.toAppLogin(dto);
        return Result.success(userLoginVO);
    }

    /*
    * 查询菜品即套餐分类
    * */
    @GetMapping("/category/list")
    public Result selectCategory(Integer type){

        List<Category> categories = userService.selectCategory(type);
        return Result.success(categories);
    }
    /*
    * 根据菜品分类id查询菜品
    * */
    @GetMapping("/dish/lish")
    public Result selectDishByCategoryId(Long id){
        List<DishVO> dishVOList = userService.selectDishByCategoryId(id);
        return Result.success(dishVOList);
    }

    /*
    * 根据菜品分类id查询套餐
    * */
    @GetMapping("/setmeal/list")
    public Result selectSetmealByCategoryId(Long id){
        List<Setmeal> setmeals = userService.selectSetmealByCategoryId(id);
        return Result.success(setmeals);
    }
    /*
    * 根据套餐id查询包含的菜品
    * */
    @GetMapping("/setmeal/dish/{setmealId}")
    public Result selectDishBySetmealId(@PathVariable(name = "setmealId") Long id ){
        List<DishItemVO> dishItemVOList = userService.selectDishBySetmealId(id);
        return Result.success(dishItemVOList);
    }
}
